package com.acme.bankapp.domain.bank;

import java.io.Serializable;
import com.acme.bankapp.Exception.OverdraftLimitExceededException;

public class SavingAccount implements Account,Serializable {

	private int balance;
	private int Id;
	
	public SavingAccount(int balance, int id){
		this.balance=balance;
		Id=id;
	}
	
	@Override
	public int hashCode() {
		return Id;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Id != other.Id) return false;
		return true;
	}
	
	@Override
	public int getBalance() {
		return balance;
	}

	@Override
	public void deposit(double x) {
		balance +=x;
	}

	@Override
	public void withdraw(double x) throws OverdraftLimitExceededException {
		if(x<=balance){
			balance -=x;
		}
		else {
			throw new OverdraftLimitExceededException(balance);
		}
	}


	@Override
	public double maximumAmountToWithdraw() {
		return balance;
	}

	@Override
	public int decimalValue() {
		return(Math.round(balance));
	}

	@Override
	public int getOverdraft() {
		return 0;
	}

}
